package it.agm.fanta.adapter;

import it.agm.fanta.FantaserviceApp;
import it.agm.fanta.R;
import it.agm.fanta.model.LegaSquadra;

import java.util.ArrayList;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TypeSnippetAdapter extends ArrayAdapter<String> {
	
	public TypeSnippetAdapter(Context context, int textViewResourceId,
			ArrayList<String> objects) {
        super(context, textViewResourceId, objects);
    }

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.drawer_snippet_item, null); 
        convertView = initView(position,convertView);
        return convertView;
    }

	/**
	 * @param position
	 * @return
	 */
	public View initView(int position,View convertView) {
		
		
        TextView nomeType = (TextView)convertView.findViewById(R.id.text_pirates);
        ImageView imageType = (ImageView) convertView.findViewById(R.id.img_pirates);
        String type = getItem(position);
        Resources resources = FantaserviceApp.currentActivity().getResources();
        Drawable drawable = resources.getDrawable(resources.getIdentifier(""+type.toLowerCase(), 
        		"drawable", FantaserviceApp.currentActivity().getPackageName()));
        imageType.setImageDrawable(drawable);
        nomeType.setText(""+type);
		return convertView;
	}
	@Override
    public View getDropDownView(int position, View convertView,
                                ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.spinner_dropdown_item, null); 
       
        return initView(position,convertView);
    }
	
	

}
